<?php

namespace common\components\system;

use Yii;
use common\helpers\ArrayHelper;
use common\models\mongo\SystemLog;

/**
 * Description of AdminLog
 *
 * @author emhome
 */
class LoginRecord extends BaseLogRecord {

    public $modelClass = SystemLog::class;

    /**
     * 后台登录
     * @param obj $event
     * @return mixed
     */
    public static function afterLogin($event) {
        $sender = $event->sender;
        if ($sender instanceof \yii\web\User) {
            $description = '后台登录';
            $user = [];
            if ($event->identity) {
                $user = $event->identity->toArray();
            }
            $data = ArrayHelper::merge($user, [
                'cookieBased' => $event->cookieBased,
                'duration' => $event->duration,
            ]);
            self::log([
                'table' => $event->identity::tableName(),
                'class' => $sender::className(),
                'type' => SystemLog::TYPE_LOGIN,
                'description' => $description,
                'data' => $data,
            ]);
        }
    }

}
